<template>
    <div class="list" ref="wraper">

       <div class="" style="overflow: hidden;">
            <div class="area">
                <div class="title border-topbottom">当前城市</div>
                <div class="button-list">
                    <div class="button-wrapper">
                    <div class="button">
                        {{this.currencity}}</div>  
                    </div>
                </div>
            </div>
            <div class="area">
                <div class="title border-topbottom" >热门城市</div>
                <div class="button-list">
                    <div class="button-wrapper" 
                        v-for="item of bbses" 
                        :key="item.id" 
                        @click="handleclick(item.name)"
                        >
                       <div class="button"> {{item.name}}</div>  
                    </div>
                </div>
            </div>
            <div class="area" v-for="(item,key) of aases" :key="key"
              :ref="key"
            >
                <div class="title border-topbottom">{{key}}</div>
                <div class="item-list" >
                    <div class="item  border-bottom"  
                      v-for="instem of item"
                      :key="instem.id"
                       @click="handleclick(instem.name)"
                    >
                     {{instem.name}}
                    </div>
                </div>
            </div>
        </div> 
    </div>
</template>

<script>
import bscroll from 'better-scroll'
import {mapState , mapMutations} from 'vuex'
export default {
    name:'citylist',
    props:{
        aases : Object,
        bbses : Array ,
        les : String
    },
    computed:{
        ...mapState({
            currencity:'city'
        })
    },
    methods:{
        handleclick(city){
             //修改 $store.state.city 时 必须使用 dispatch 方法
            // this.$store.commit('changecity',city) 简单没有批量的操作commit
             this.$store.dispatch('changecity',city)
            //  this.changecity(city)
             this.$router.push('/')
        }
        // ,  cuwu
        // ...mapMutations(['changecity'])  vuex 管理方法
    },
    mounted() {
        this.scroll=new bscroll(this.$refs.wraper)
    },
    watch:{
        les(){
            if(this.les){
                const element=this.$refs[this.les][0]
                this.scroll.scrollToElement(element)
            }
        }
    }
}
</script>


<style lang="stylus" scoped>
       @import '~styles/varibles.styl' 
        .border-topbottom
            &:before
                border-color #cccccc
            &:after
                border-color #cccccc
        .border-bottom
            &:before
                border-color #cccccc
        .list
           overflow hidden
           position absolute
           top 1.58rem
           left 0
           bottom 0 
           right 0 
           .title
                line-height  .54rem
                background  #eeeeee
                padding-left .2rem
                color #666
                font-size .26rem
            .button-list
                padding .1rem 0.6rem .1rem .1rem
                overflow hidden
                .button-wrapper
                    float left
                    width 33.33% 
                    padding .1rem 
                    box-sizing border-box
                    .button
                        padding .1rem 0
                        text-align center
                        border 0.02rem solid #cccccc
                        border-radius 0.06rem
            .item-list
            .item
             line-height .76rem
             color #666
             padding-left .2rem


                           
                
       
       
</style>



